const reg = /^[0][1-9]{2,3}[0-9]{5,10}$/;
const kreg1 = /^[\u4e00-\u9fa5a-zA-Z]+$/;
var checkPhone = (rule, value, callback) => {
    if (kreg1.test(value)) {
        callback(new Error('请输入数字,例子:0897123456'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的办公电话，例子:0897123456'));
    }
    callback();
};
const kreg = /^1[3456789]\d{9}$/;
var checkTelePhone = (rule, value, callback) => {
    if (!value) {
        callback(new Error('手机号不能为空'));
    } else if (!kreg.test(value)) {
        callback(new Error('请输入正确的手机号'));
    }
    callback();
};
var checkName = (rule, value, callback) => {
    if (!value) {
        callback(new Error('请输入姓名'))
    } else {
        const reg = /^[\u4e00-\u9fa5]+$/
        const ereg = /^[a-zA-Z]+$/ // 验证没有空格的英文名
        if (value.length < 20 && (reg.test(value) || ereg.test(value))) {
            callback()
        } else {
            return callback(new Error('请输入正确的名称'))
        }
    }
};
var checkMaxChars = (rule, value, callback) => {
    if (value !== undefined && value !== null && value.length > rule.len) {
        return callback(new Error('最多输入' + rule.len + '个字符'));
    }
    callback();
};
var checkMaxCharsNonNull = (rule, value, callback) => {
    if (!value) {
        return callback(new Error('不能为空'));
    } else if (value.length > rule.len) {
        return callback(new Error('最多输入' + rule.len + '个字符'));
    }
    callback();
};
var checkPercent = (rule, value, callback) => {
    const reg = /^(100|[1-9]?\d(\.\d\d?\d?)?)$|0$/;
    if(!reg.test(value)){
        return callback(new Error('请输入正确的百分比'));
    }
    callback();
};
var checkPostcode = (rule, value, callback) => {
    const reg = /^[1-9]\d{5}$/g;
    if(!reg.test(value)){
        return callback(new Error('请输入正确的邮政编码'));
    }
    callback();
};
var checkFax = (rule, value, callback) => {
    const reg =  /^(\d{3,4}-)?\d{7,8}$/;
    if(!reg.test(value)){
        return callback(new Error('传真格式为:XXX-12345678或XXXX-1234567或XXXX-12345678'));
    }
    callback();
};
var checkMoney = (rule, value, callback) => {
    const reg =  /^([1-9]+|[1-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$/;
    if(!reg.test(value)){
        return callback(new Error('不符合规范'));
    }
    callback();
};

export default {
    checkName,
    checkPhone,
    checkTelePhone,
    checkMaxChars,
    checkMaxCharsNonNull,
    checkPercent,
    checkPostcode,
    checkFax,
    checkMoney
}